package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.BaseTeacherDao;
import com.itheima.edu.info.manager.dao.OtherTeacherDao;
import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;
import com.itheima.edu.info.manager.factory.TeacherDaoFactory;

public class TeacherService {
    private BaseTeacherDao dao = TeacherDaoFactory.getTeacherDao();

    public boolean isExists(String id) {
        Teacher[] teac = dao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < teac.length; i++) {
            Teacher tea = teac[i];
            if (tea != null && tea.getId().equals(id)) {
                flag = true;
            }
        }
        return flag;
    }

    public boolean addTeacher(Teacher tea) {
        return dao.addTeacher(tea);
    }

    public Teacher[] findAllTeacher() {
        Teacher[] tea = dao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < tea.length; i++) {
            Teacher t = tea[i];
            if (t != null) {
                flag = true;
            }
        }
        if (flag) {
            return tea;
        } else {
            return null;
        }
    }

    public void deleteTeacherById(String delId) {
        dao.deleteTeacherById(delId);
    }

    public void updateTeacher(String updateId, Teacher newtea) {
        dao.updateTeacher(updateId, newtea);
    }
}
